using System;
using System.Collections.Generic;
//using System.Text;
using System.IO;
using Petra.Gis.Geometry;
using Petra.Gis.Geometry.Support;
using Petra.Gis.DataServices.WKB.Support;

namespace Petra.Gis.DataServices.WKB
{
	public partial class GeometryFactory
	{

    /***********************************************
    * 28.8.2007
    * 
    * creates Point
    * from wkb blob
    * 
    * asida@centrum.cz, initial implementation
    *************************************************/
    private static GeometryBase binaryToPoint(BinaryReader mBReader/*, int arrayOffset*/, System.Type parentGeomType)
    {
      //read data endian first
      //mBReader.BaseStream.Position = arrayOffset;
      WKB.ByteOrder dataEndian = (WKB.ByteOrder)mBReader.ReadByte();

      //skip geometry type
      mBReader.BaseStream.Position += 4;

      CoordinateList Coords = CoordinateListConverter.ToCoordinateList(mBReader/*, arrayOffset + 5*/, 1, Dimension.dim2D, dataEndian);
      Point oGeom = new Point();
      oGeom.coordList = Coords;

      return oGeom;
    }






    /***********************************************
    * 28.8.2007
    * 
    * creates wkb blob 
    * from Point
    * 
    * asida@centrum.cz, initial implementation
    *************************************************/
    private static byte[] pointToBinary(GeometryBase geometry)
    { 
      int lBlobSize;

      Point _tmpPoint = (Point)geometry;

      lBlobSize = 1 + 4 + (16);

      System.IO.MemoryStream oIMStream = new System.IO.MemoryStream(lBlobSize);
      System.IO.BinaryWriter mBWriter = new System.IO.BinaryWriter(oIMStream);

      oIMStream.Position = 0;

      mBWriter.Write((byte)EndianConverter.GetCurrentPlatformEndian());
      mBWriter.Write((Int32)WKB.WKBGeometryTypes.Point);
      mBWriter.Write(_tmpPoint.coordList.ToArray(Dimension.dim2D));

      return oIMStream.ToArray();
    }
	}
}
